package com.yl.applicationsecurity.controller;

import com.github.pagehelper.PageInfo;
import com.yl.applicationsecurity.pojo.Inspection;
import com.yl.applicationsecurity.pojo.InspectionConfiguration;
import com.yl.applicationsecurity.pojo.Result;
import com.yl.applicationsecurity.service.InspectionService;
import com.yl.applicationsecurity.service.ScriptStateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@RestController
@RequestMapping("/inspection")
public class InspectionController {


    @Autowired
    private InspectionService inspectionService;

    @Autowired
    private ScriptStateService scriptStateService;

    @PostMapping("/list")
    public Result list(String[] nationSelect,Inspection  inspection, @RequestParam(required = false) Date[] startAndEndDate,@RequestParam(defaultValue = "1", value = "pageNum")Integer pageNum
            ,@RequestParam(defaultValue = "10", value = "pageSize")Integer pageSize ){
        PageInfo<Inspection> InspectionList = null;
        if(startAndEndDate!=null&&startAndEndDate.length!=2){
            InspectionList =  inspectionService.findListByInspection(nationSelect,inspection,null,null,pageNum,pageSize);
        }else{
            InspectionList =  inspectionService.findListByInspection(nationSelect,inspection,startAndEndDate[0],startAndEndDate[1],pageNum,pageSize);
        }

        return Result.success(InspectionList);
    }


    @RequestMapping("/updateStatus")
    public Result updateStatus(HttpServletRequest request,String[]  ids,Integer updateStatus) {


        if(inspectionService.updateStatus(  ids, updateStatus)!=0){
            return  Result.success("修改成功");
        }else{
            return  Result.error("修改失败");
        }


    }


    @RequestMapping("/insert")
    public Result insert(HttpServletRequest request, Inspection inspection) {
        scriptStateService.updateDate("登录入口巡检");
        if(inspectionService.insert(inspection)!=0){
            return  Result.success("添加成功");
        }else{
            return  Result.error("添加失败");
        }
    }



}
